/*
Disclaimer of Warranty: THE PACKAGE IS PROVIDED
BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS'
AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
THE IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT
ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW.
UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF
THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


(c) Copyright 2013 Edward Principe
All Rights Reserved

*/
#include "varnode.h"

///////////////////////////////////////////////////////////////////
// Static Members
///////////////////////////////////////////////////////////////////
TYPE_WORD VarNode::offset_global = TYPE_NULL; // Global variable offset
TYPE_WORD VarNode::stack_offset = TYPE_NULL; // Stack offset

//////////////////////////////////////////////////////////////////
// Init: Initializes class
//////////////////////////////////////////////////////////////////
void VarNode::Init()
{
	type = VARTYPE_VARANT;
	is_stack = false;

	offset = TYPE_NULL;

	dim = 0;
	bound = NULL;
}

///////////////////////////////////////////////////////////////////
// Copy: Copies the structure
///////////////////////////////////////////////////////////////////
void VarNode::Copy(const VarNode& rhs)
{
	// Same object?
	if (this == &rhs)
		return;

	// Delete current boundry
	delete[] bound;
	bound = NULL;

	// Copy structure
	label = rhs.label;
	object_label = rhs.object_label;

	type = rhs.type;
	is_stack = rhs.is_stack;

	offset = rhs.offset;

	dim = rhs.dim;

	if (dim != 0)
	{
		bound = new TYPE_WORD[dim];

		for (unsigned int i = 0; i < dim; i++)
			bound[i] = rhs.bound[i];
	}

	objects.erase(objects.begin(), objects.end());
	
	for (vector<VarNode>::const_iterator i = rhs.objects.begin(); i != rhs.objects.end(); i++)
		objects.push_back(static_cast<VarNode>(*i));

	list_struct.erase(list_struct.begin(), list_struct.end());

	for (list<VarNode>::const_iterator i = rhs.list_struct.begin(); i != rhs.list_struct.end(); i++)
		list_struct.push_back(static_cast<VarNode>(*i));
}
/////////////////////////////////////////////////////////////////////////
// Reset: Reset structure
/////////////////////////////////////////////////////////////////////////
void VarNode::Reset()
{
	label = L"";
	object_label = L"";

	type = VARTYPE_VARANT;

	is_stack = false;

	offset = TYPE_NULL;

	dim = 0;

	delete[] bound;

	bound = NULL;

	list_struct.erase(list_struct.begin(), list_struct.end());

	 
}